package com.example.aboutspringboot.mapper;

import com.example.aboutspringboot.entity.User;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

@Mapper
public interface UserMapper {

    //按名查找一个用户信息
    @Select("select username,password,address,phone,money from user where username=#{username}")
    User selectOneUserByUsername(String username);

    //按用户名和密码查找一个用户信息
    @Select("select username,password,address,phone,money from user where username=#{username} and password=#{password}")
    User selectOneUser(String username,String password);

    //添加用户信息，不需要钱
    @Insert("insert into user(username,password,address,phone)values(#{username},#{password},#{address},#{phone})")
    int insertOneUser(User user);

    //修改用户信息，不允许改名
    @Update("update user set password=#{password},address=#{address},phone=#{phone},money=#{money} where username=#{username}")
    int updateOneUser(User user);

    //充钱
    @Update("update user set money=#{money} where username=#{username}")
    int addMoney(String username, double money);
}
